import greenfoot.*;  // (Actor, World, Greenfoot, GreenfootImage)

public class CrabWorld extends World
{
    /**
     * }
     * Create the crab world (the beach). Our world has a size 
     * of 560x560 cells, where every cell is just 1 pixel.
     */
    public CrabWorld() 
    {
        super(560, 560, 1);
        Crab c = new Crab();
        addObject(c, 100, 150);
        for (int i = 0; i < 10; i++){
            for(int j = 0; j <= i; j++){
                Worm w = new Worm();
                addObject(w, 50 + i * 50, 50 + j * 50);
            }
        }
        for (int i = 0; i < 5; i++){
            Lobster w = new Lobster();
            addObject(w, 50 + i * 50, 300);
        }
        showScore(0);
    }

    public void drawNum(int num){
        GreenfootImage image = getBackground();
        if(num ==  4){
            Color color = new Color(255, 0, 0);
            image.setColor(color);
            Font font=image.getFont();
            font=font.deriveFont(30);
            image.setFont(font);
            //image.drawString("吃虫数：" + num, 5, 30);
            image.drawString("成功", 250,300);
            Greenfoot.stop();
        }
    }

    public void a(int x){
        GreenfootImage image = getBackground();
        Color color = new Color(255, 0, 0);
        image.setColor(color);
        if(x > 0){
            Font font=image.getFont();
            font=font.deriveFont(30);
            image.setFont(font);
            image.drawString("失败", 250,300);
            Greenfoot.stop();
        }
    }

    public void showScore(int count){
        GreenfootImage bg = getBackground();
        bg.setColor(Color.WHITE);
        bg.fillRect(50, 0, 90, 30);
        bg.setColor(Color.BLUE);
        bg.setFont(new Font(18));
        bg.drawString("吃虫数: " + count, 50, 20);
    }

    /**
     * 为程序启动准备场景
     * 即：创建初始的物体并将其加入场景。
     */
    private void prepare()
    {
    }
}
  